Crate atoi

source ·
Expand description

A crate for parsing integers directly form ASCII ([u8]) without encoding them into utf8 first. The name is inspired by the famous C function.

Using str::from_utf8 and str::parse is likely to be more idiomatic. Use this crate if you want to avoid decoding bytes into utf8 (e.g. for performance reasons).

Note that if you want to know how much of the input has been used, you can use the FromRadix10 trait, for example:

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> ((&[u8], Option<I>)) {
    match I::from_radix_10(text) {
        (_, 0) => (text, None),
        (n, used) => (&text[used..], Some(n)),
    }
}

Enums

Representation of a numerical sign

Traits

Types implementing this trait can be parsed from a positional numeral system with radix 10

Functions

Converts an ascii character to digit
Parses an integer from a slice.